<template>
  <div class="mall-layout">
    <el-container>
      <el-header height="60px">
        <div class="header-content">
          <router-link to="/mall" class="logo">
            <el-icon><Shop /></el-icon>
            电商商城
          </router-link>

          <el-menu
            mode="horizontal"
            :router="true"
            class="nav-menu"
          >
            <el-menu-item index="/mall">首页</el-menu-item>
            <el-menu-item index="/mall/coupons">优惠券</el-menu-item>
            <el-menu-item index="/mall/promotions">活动专区</el-menu-item>
          </el-menu>

          <div class="user-menu">
            <template v-if="userStore.isAuthenticated">
              <el-button-group>
                <el-button :icon="ShoppingCart" @click="$router.push('/mall/cart')">
                  购物车
                  <el-badge v-if="cartStore.totalItems" :value="cartStore.totalItems" />
                </el-button>
                <el-button :icon="Document" @click="$router.push('/mall/orders')">我的订单</el-button>
                <el-button :icon="SwitchButton" @click="handleLogout">退出</el-button>
              </el-button-group>
            </template>
            <template v-else>
              <el-button type="primary" @click="$router.push('/login')">登录</el-button>
            </template>
          </div>
        </div>
      </el-header>

      <el-main>
        <div class="main-content">
          <router-view></router-view>
        </div>
      </el-main>

      <el-footer height="auto">
        <div class="footer-content">
          <el-row :gutter="40">
            <el-col :span="8">
              <h3>关于我们</h3>
              <p>我们致力于为您提供优质的购物体验，让每一次消费都充满愉悦。</p>
            </el-col>
            <el-col :span="8">
              <h3>客户服务</h3>
              <el-space direction="vertical">
                <el-link>购物指南</el-link>
                <el-link>配送方式</el-link>
                <el-link>支付方式</el-link>
                <el-link>售后服务</el-link>
              </el-space>
            </el-col>
            <el-col :span="8">
              <h3>联系我们</h3>
              <el-space direction="vertical">
                <p><el-icon><Phone /></el-icon> 400-xxx-xxxx</p>
                <p><el-icon><Message /></el-icon> support@example.com</p>
                <p><el-icon><Location /></el-icon> 北京市朝阳区xxx大厦</p>
              </el-space>
            </el-col>
          </el-row>
        </div>
        <div class="footer-bottom">
          <p>&copy; 2024 电商商城. All rights reserved.</p>
        </div>
      </el-footer>
    </el-container>
  </div>
</template>

<script setup lang="ts">
import { useRouter } from 'vue-router'
import { useUserStore } from '@/stores/user'
import { useCartStore } from '@/stores/cart'
import { 
  Shop, 
  ShoppingCart, 
  Document, 
  SwitchButton,
  Phone,
  Message,
  Location
} from '@element-plus/icons-vue'

const router = useRouter()
const userStore = useUserStore()
const cartStore = useCartStore()

const handleLogout = () => {
  userStore.logout()
  router.push('/login')
}
</script>

<style scoped>
.mall-layout {
  min-height: 100vh;
  width: 100vw;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
}

.el-container {
  min-height: 100vh;
  width: 100%;
  display: flex;
  flex-direction: column;
}

.el-header {
  background-color: var(--el-bg-color);
  border-bottom: 1px solid var(--el-border-color-light);
  position: fixed;
  width: 100%;
  top: 0;
  left: 0;
  right: 0;
  z-index: 1000;
  padding: 0;
}

.header-content {
  max-width: 1400px;
  width: 100%;
  height: 100%;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  box-sizing: border-box;
}

.logo {
  font-size: 1.5rem;
  font-weight: bold;
  color: var(--el-text-color-primary);
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
}

.logo .el-icon {
  font-size: 24px;
  color: var(--el-color-primary);
}

.nav-menu {
  flex: 1;
  justify-content: center;
  border-bottom: none;
  margin: 0 20px;
}

.user-menu {
  display: flex;
  gap: 12px;
  align-items: center;
  white-space: nowrap;
}

.el-main {
  flex: 1;
  width: 100%;
  padding: 0;
  margin-top: 60px;
  background-color: var(--el-bg-color-page);
  display: flex;
  flex-direction: column;
  min-height: calc(100vh - 60px - 300px);
  box-sizing: border-box;
}

.main-content {
  flex: 1;
  max-width: 1400px;
  width: 100%;
  margin: 0 auto;
  padding: 20px;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
}

.el-footer {
  width: 100%;
  background-color: var(--el-bg-color-page);
  padding: 60px 0 0;
  margin-top: auto;
  box-sizing: border-box;
  position: relative;
  z-index: 10;
}

.footer-content {
  max-width: 1400px;
  width: 100%;
  margin: 0 auto;
  padding: 0 20px;
  box-sizing: border-box;
  background-color: var(--el-bg-color-page);
}

.footer-content h3 {
  font-size: 18px;
  color: var(--el-text-color-primary);
  margin-bottom: 20px;
}

.footer-content p {
  color: var(--el-text-color-regular);
  line-height: 1.6;
}

.footer-content .el-icon {
  margin-right: 8px;
  color: var(--el-text-color-secondary);
}

.footer-bottom {
  margin-top: 60px;
  padding: 20px;
  text-align: center;
  border-top: 1px solid var(--el-border-color-lighter);
  color: var(--el-text-color-secondary);
  background-color: var(--el-bg-color);
  width: 100%;
  box-sizing: border-box;
}

@media (max-width: 1440px) {
  .header-content,
  .main-content,
  .footer-content {
    max-width: 100%;
  }
}

@media (max-width: 768px) {
  .header-content {
    padding: 0 10px;
  }

  .nav-menu {
    display: none;
  }

  .user-menu .el-button-group {
    display: none;
  }

  .el-footer {
    padding: 40px 0 0;
  }

  .footer-content {
    padding: 0 10px;
  }

  .el-col {
    width: 100%;
    margin-bottom: 30px;
  }
}
</style> 